<?php

namespace App\Modules\Home\Models;


use Illuminate\Database\Eloquent\Model;

/**
 * Class Article 文章
 * @package App\Modules\Task\Models
 */
class Article extends Model
{
    protected $table = 'article';

    protected $fillable = ['id','user_id', 'category_id', 'title', 'content', 'created_at', 'updated_at', 'status'];

    /**
     * 文章列表
     */
    static function getList($category_id)
    {
        return self::where('category_id',$category_id)->where('status',1)->orderBy('sort','desc')->get();
    }

    /**
     * 获取文章详情
     * @param $id 任务id
     * @return mixed
     */
    static function getArticle($category_id)
    {
        return self::where('category_id',$category_id)->where('status',1)->first();
    }

    /**
     * 添加文章
     * @param $param
     * @return mixed
     */
    static function addArticle($param)
    {
        // TODO check
        return self::create($param);
    }

    /**
     * 更新文章
     * @param $param
     * @return mixed
     */
    static function updateArticle($param)
    {
        // TODO check
        return self::where('id',$param['id'])->update($param);
    }

}